package com.example.sms.exception;




import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * @author RENCHI
 * @date 2024/1/16 14:53
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

//    @ExceptionHandler(MethodArgumentNotValidException.class)//
//    public R handleBizException(MethodArgumentNotValidException e){
//        return R.failed(e.getBindingResult().getFieldError().getDefaultMessage());
//    }
//    @ExceptionHandler(ConstraintViolationException.class)//ConstraintViolationException
//    public R handleBizException(ConstraintViolationException e){
//        return R.failed(e.getMessage());
//    }
    @ExceptionHandler(CustomerException.class)
    public R handleBizException(CustomerException e){
        return R.fail(e.getExceptionCode(),e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public R handleBizException(Exception e){
        System.out.println(e.getMessage());
        return R.fail("系统开小差了");
    }
//    @ExceptionHandler(SignatureVerificationException.class)
//    public R handleBizException(SignatureVerificationException e){
//        return R.failed("token已被篡改");
//    }
//    @ExceptionHandler(TokenExpiredException.class)
//    public R handleException(TokenExpiredException e){
//        return R.failed("token已过期");
//    }
//    @ExceptionHandler(AuthorizationException.class)
//    public R handleBizException(AuthorizationException e){
//        return R.noperm();
//    }

}
